<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Admin System</title>
    <link rel="stylesheet" href="/public/admin/layui/css/layui.css">
    <style>
        body{
            background-color: #F2F2F2;
        }
        .oa-container {
            /*background-color: white;*/
            position: absolute;
            width: 400px;
            height: 220px;
            top: 50%;
            left: 50%;
            padding: 20px;
            margin-left: -200px;
            margin-top: -150px;
            border: green 1px solid;
        }
        #username,#password {
            text-align: center;
            font-size: 16px;
        }
    </style>
</head>

<body>
<div class="oa-container">
    <h1 style="text-align: center;margin-bottom: 20px;border-bottom: #2d93ca 1px solid;">Admin System</h1>
    <form class="layui-form" action="{:url('index/login')}">
        <div class="layui-form-item">
            <input type="text" id="username" name="username" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <input type="password" id="password" name="password" placeholder="请输入密码" value="admin123456" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登录</button>
        </div>
    </form>
</div>
<!-- 你的 HTML 代码 -->
 
<script src="/public/admin/layui/layui.js"></script>
<script>
layui.use(['jquery', 'layer', 'form'], function(){
    var $ = layui.jquery
        ,layer = layui.layer
        ,form = layui.form;

    //表单submit监听
    form.on('submit(login)', function(data){
        var action = $('.layui-form').attr('action');
        var ary = data.field;

        console.log('login',action)

        $.ajax({
            url: action,
            data: ary,
            type: "post",
            dataType:'json',
            success:function(res){
                console.log(res);
                //数据处理
                if(res.code===1){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function (index) {
                        window.location.href = res.data.url;
                    });
                }
                if(res.code===0){
                    layer.msg(res.msg, {icon:2,time:1000});
                }
            },error: function(res){
                console.log(res);
                layer.msg('致命错误');
            }
        });
        return false;
    });
});
</script> 
</body>
</html>